import openai

# 设置你的 OpenAI API 密钥
# openai.api_key = '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'
openai.api_key = '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'




def call_chatgpt(prompt):
    try:
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",  # 指定模型
            messages=[
                {"role": "user", "content": prompt}  # 输入内容
            ]
        )
        return response.choices[0].message["content"]
    except Exception as e:
        return f"API 调用失败: {str(e)}"

# 调用示例
user_input = "你好，用一句话解释 Python 是什么？"
response = call_chatgpt(user_input)
print("回答:", response)